const axios = require('axios');

const apiKey = '2tmP42B6ARNuf5gtsOSbX0ZA';
const secretKey = '7qJTxfi7nx5oGJenZQiZ8xXVY4zTNcqv';
//const API_KEY = '7qJTxfi7nx5oGJenZQiZ8xXVY4zTNcqv';
//const SECRET_KEY = '7qJTxfi7nx5oGJenZQiZ8xXVY4zTNcqv';

const getAccessToken = async () => {
    try {
        const response = await axios.post(`https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=${apiKey}&client_secret=${secretKey}`);
        const accessToken = response.data.access_token;
        return accessToken;
    } catch (error) {
        console.error('获取 access_token 失败:', error);
        return null;
    }
};

// 使用示例
getAccessToken().then((token) => {
    if (token) {
        console.log('获取的 access_token:', token);
    }
});